package bigdata.backend.datasource.test;

import bigdata.backend.datasource.entity.Datasource;
import bigdata.backend.datasource.mapper.DatasourceMapper;
import bigdata.backend.datasource.service.SchemaSyncService;
import bigdata.backend.datasource.utils.SyncTableResult;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

@SpringBootTest
public class TestSchemaSyncService {
    @Autowired
    private DatasourceMapper datasourceMapper;

    @Autowired
    private SchemaSyncService schemaSyncService;

    public Datasource getDataSource(String datasourceId) {
        Datasource ds = datasourceMapper.selectById(datasourceId);
        return ds;
    }

    @Test
    public void test() {
        Datasource ds1 = getDataSource("1001"); // mysql
        Datasource ds2 = getDataSource("1002"); // mysql
        Datasource ds3 = getDataSource("3001"); // pg
        Datasource ds4 = getDataSource("2001"); // doris
        // mysql -> mysql
//        SyncTableResult syncTableResult = schemaSyncService.syncTable(ds1, ds2, "test_user", "test_mysql2mysql");

        // mysql -> pg
//        SyncTableResult syncTableResult = schemaSyncService.syncTable(ds1, ds3, "test_user", "test_mysql2pg");

        // mysql -> doris
//        SyncTableResult syncTableResult = schemaSyncService.syncTable(ds1, ds4, "test_user", "test_mysql2doris");

        // pg -> pg
//        SyncTableResult syncTableResult = schemaSyncService.syncTable(ds3, ds3, "test_mysql2pg", "test_pg2pg");

        // pg -> mysql
//        SyncTableResult syncTableResult = schemaSyncService.syncTable(ds3, ds1, "test_mysql2pg", "test_pg2mysql");

        // pg -> doris
//        SyncTableResult syncTableResult = schemaSyncService.syncTable(ds3, ds4, "test_mysql2pg", "test_pg2doris");

        // doris -> doris
//        SyncTableResult syncTableResult = schemaSyncService.syncTable(ds4, ds4, "test_mysql2doris", "test_doris2doris");

        // doris -> mysql
//        SyncTableResult syncTableResult = schemaSyncService.syncTable(ds4, ds1, "test_mysql2doris", "test_doris2mysql");

        // doris -> pg
        SyncTableResult syncTableResult = schemaSyncService.syncTable(ds4, ds3, "test_mysql2doris", "test_doris2pg");


        System.out.println(syncTableResult);
    }

    @Test
    public void test2() {
        Datasource ds1 = getDataSource("1001"); // mysql
        Datasource ds2 = getDataSource("1002"); // mysql
        Datasource ds3 = getDataSource("3001"); // pg
        Datasource ds4 = getDataSource("2001"); // doris
        String ddl = schemaSyncService.generateCreateTableDdl(ds4, ds3, "test_mysql2doris", "test_doris2mysql");
        System.out.println(ddl);
    }
}
